package com.pureut.scheduling.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.scheduling.domain.SchedulingWeight;
import com.pureut.scheduling.domain.dto.SchedulingPlanDto;
import com.pureut.scheduling.domain.vo.SchedulingWeightVo;
import com.pureut.scheduling.domain.vo.SchedulingWillVo;
import com.pureut.scheduling.service.ISchedulingWillService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 排产条件控制层
 * @Date 22-12-29
 * @Author hl
 **/
@RestController
@RequestMapping("/condition")
public class SchedulingWillController extends BaseController  {

    @Resource
    private ISchedulingWillService schedulingWillService;

    /**
     * 查询排程条件信息
     */
    @RequiresPermissions("schedule:scheduleConfig:condition:list")
    @GetMapping("/list")
    public TableDataInfo list(SchedulingWillVo schedulingWillVo)
    {
        startPage();
        List<SchedulingPlanDto> list = schedulingWillService.selectWillList(schedulingWillVo);
        return getDataTable(list);
    }

    /**
     * 修改优先排序或开启关闭
     */
    @RequiresPermissions("schedule:scheduleConfig:condition:sort")
    @Log(title = "标准工时", businessType = BusinessType.UPDATE)
    @PutMapping("/sort")
    public AjaxResult edit(@RequestBody SchedulingWillVo schedulingWillVo) {
        return toAjax(schedulingWillService.updateSchedulingWillSort(schedulingWillVo));
    }

    /**
     * 查询配比信息
     */
    @RequiresPermissions("schedule:scheduleConfig:condition:weightList")
    @GetMapping("/weightList")
    public TableDataInfo weightList(SchedulingWeightVo schedulingWeightVo) {
        startPage();
        List<SchedulingWeight> list = schedulingWillService.selectWeightList(schedulingWeightVo);
        return getDataTable(list);
    }

    /**
     * 根据配比id查询详情
     */
    @RequiresPermissions("schedule:scheduleConfig:condition:getInfo")
    @GetMapping(value = "/{weightId}")
    public AjaxResult getInfo(@PathVariable Long weightId) {
        return AjaxResult.success(schedulingWillService.selectWeightById(weightId));
    }

    /**
     * 新增配比信息
     */
    @RequiresPermissions("schedule:scheduleConfig:condition:add")
    @Log(title = "新增配置信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody SchedulingWeightVo schedulingWeightVo) throws Exception {
        return toAjax(schedulingWillService.insertWeight(schedulingWeightVo));
    }

    /**
     * 修改配比信息
     */
    @RequiresPermissions("schedule:scheduleConfig:condition:edit")
    @Log(title = "修改配置信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody SchedulingWeightVo schedulingWeightVo) throws Exception {
        return toAjax(schedulingWillService.updateWeight(schedulingWeightVo));
    }

    /**
     * 批量删除配比信息
     */
    @RequiresPermissions("schedule:scheduleConfig:condition:remove")
    @Log(title = "批次删除配置信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{weightId}")
    public AjaxResult remove(@PathVariable("weightId")String weightId) throws Exception {
        return toAjax(schedulingWillService.deleteWeightByIds(weightId));
    }
}
